package com.lagou.controller;

import com.github.pagehelper.PageInfo;
import com.lagou.pojo.Article;
import com.lagou.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lbq
 * @version 1.0
 * @date 2021/1/12 21:47
 */
// @RestController
@RequestMapping("/article")
@Controller
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @GetMapping("/list")
    public String articleList(Model model,
                              @RequestParam(defaultValue = "1", required = false) int pageNum,
                              @RequestParam(defaultValue = "2", required = false) int pageSize) {
        PageInfo<Article> pageInfo = articleService.selectByPage(pageNum, pageSize);
        model.addAttribute("pageInfo", pageInfo);
        System.out.println(pageInfo.toString());
        return "index";
    }
}
